package com.solocredit.finance.utils.dialog

import android.annotation.SuppressLint
import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import com.solocredit.finance.R
import com.solocredit.finance.databinding.DialogMullaLuckyDrawPointsBinding
import com.solocredit.finance.http.HttpHelper
import com.solocredit.finance.utils.event.MullaEventType

/**
 * MullaFlow
 * @Author wwdeng
 * @CreateTime: 2024/7/8 15:50
 * @Annotation：抽奖获得积分 提示dialog
 */
class LuckyDrawPointsDialog: ProDialog {

    private lateinit var binding: DialogMullaLuckyDrawPointsBinding
    private var mCallback: IDialogCallback? = null
    //事件备注
    private var eventRemark = ""

    override fun initWindow() {
        val params = window?.attributes
        params?.width = WindowManager.LayoutParams.MATCH_PARENT
        params?.height = WindowManager.LayoutParams.WRAP_CONTENT
        window?.attributes = params
        window?.setWindowAnimations(R.style.dialog_scale_anim) //修改动画样式
        window?.setGravity(Gravity.CENTER)
    }

    constructor(context: Context?) : super(context) {}
    constructor(context: Context?, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    constructor(context: Context?, remark: String, callback: IDialogCallback?) : super(context) {
        mCallback = callback
        eventRemark = remark
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun getRootView(): View {
        binding = DialogMullaLuckyDrawPointsBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initView() {
    }

    override fun initListener() {
        setOnClickListener(R.id.btnThanks)
        setOnClickListener(R.id.imgClose)//关闭
    }

    override fun initData() {
    }

    /**
     * 设置获得的积分
     */
    @SuppressLint("SetTextI18n")
    fun showMullaUserBirthdayPoints(points: String){
        binding.textPoints.text = "+$points"
    }

    override fun onViewClick(v: View?) {
        dismiss()
        if (v?.id == R.id.btnThanks){
            mCallback?.onClick(v)
        }
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }

    override fun onStart() {
        super.onStart()
        HttpHelper.addMullaEventAction(MullaEventType.DIALOG.MULLA_DIALOG_LUCKY_DRAW_POINTS_SHOW)
    }

    override fun dismiss() {
        super.dismiss()
        HttpHelper.addMullaEventAction(MullaEventType.DIALOG.MULLA_DIALOG_LUCKY_DRAW_POINTS_DISMISS)
    }
}